package com.litree.service.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.litree.service.mapper.ILoginMapper;
import com.litree.service.model.LoginBean;
import com.litree.service.services.IUserService;


@SuppressWarnings({ "rawtypes", "unchecked" })
@Service
public class UserService implements IUserService {

	@Autowired
	ILoginMapper loginMapper;
	
	@Override
	public List getLoginInfo(String loginName, String pw) {
		Map param = new HashMap();
		param.put("loginName",loginName);
		param.put("pw",pw);
		return loginMapper.getLoginInfo(param);
	}


	@Override
	public List getLoginInfoByLoginName() {
		return loginMapper.getLoginInfoByLoginName();
	}
	
	@Override
	@Transactional
	public Integer setLoginInfo(LoginBean loginBean) {
		int i =loginMapper.insertLoginInfo(loginBean);
		int k = 0;
		if(null != loginBean.getLid() && i==1){
			String roleId = loginMapper.getRoleId(loginBean.getRoleName());
			loginBean.setRole_id(roleId);
			k=loginMapper.insertLoginRole(loginBean);
		}
		return k==1?k:0;
	}


	@Override
	@Transactional
	public Integer updateLoginPw(String loginName, String oldPw, String newPw) {
		Map param = new HashMap();
		param.put("loginName", loginName);
		param.put("oldPw", oldPw);
		param.put("newPw", newPw);
		return loginMapper.updateLoginPw(param);
	}


	@Override
	public Integer updateLoginImage(String loginName, String imageUrl) {
		Map param = new HashMap();
		param.put("loginName", loginName);
		param.put("imageUrl", imageUrl);
		return loginMapper.updateLoginImage(param);
	}

}
